/**
 * Created by Administrator on 2025/5/9.
 * */
#include "RadarSimulator.h"
#include <sys/socket.h>
#include <arpa/inet.h>
#include <unistd.h>

BaseObject *createRadarSimulator() {
    return new RadarSimulator();
}

void destroyRadarSimulator(BaseObject *p) {
    SAFE_DELETE(p);
}

RadarSimulator::RadarSimulator(){
    prevStep = -1;
    icrDb.intMap["step"] = 0;
    in_addr_t host_ip = 0x00000000;
    int port = 9001;
    std::thread thd(start_ts, host_ip, port, processStepUpdate, std::ref(icrDb));
    thd.detach();
}

RadarSimulator::~RadarSimulator() {
}

/* 如果使用了DDS_Reader或者DDS_Writer，则对应的input或者output前64个字节为DataFormat head首部 */
void RadarSimulator::onCompute(buffer_table_t *input, buffer_table_t *output) {
    std::this_thread::sleep_for(std::chrono::milliseconds(500));
    int step = icrDb.intMap["step"];
    if (prevStep == step) {
        return ;
    }
    prevStep = step;
    std::cout << "SimulateData.RadarSimulator step=" << step << "; !!!!!!!!!!!" << std::endl;

// LOG_INFO("(%lld)onCompute:%s", this->outputSequence, this->instanceName.c_str());

  /** 获取端口数据指针示例
   * const char *src0 = input->list[0]->data;
   * char *dest0 = output->list[0]->data;
   * */


  /** 计算示例
   * if (input->list[0]->valid) {
   *     memcpy(dest0, src0, std::min(input->list[0]->len, output->list[0]->len));
   *   }
   * */
}
